package com.itboye.mengwu.main;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.itboye.core.alert.ByAlert;
import com.itboye.core.object.BaseFragment;
import com.itboye.core.object.ResultEntity;
import com.itboye.core.object.SpPublicParams;
import com.itboye.core.utils.ObservableScrollView;
import com.itboye.core.utils.SPUtils;
import com.itboye.core.utils.XImageLoader;
import com.itboye.inageview.RoundImageView;
import com.itboye.mengwu.R;
import com.itboye.mengwu.app.MainApplication;
import com.itboye.mengwu.app.adapter.MyMengAdapter;
import com.itboye.mengwu.app.login.ui.LoginActivity;
import com.itboye.mengwu.app.login.ui.RegiterActivity;
import com.itboye.mengwu.app.logincontroller.LoginController;
import com.itboye.mengwu.app.ui.aiwujia.YouHuiQuanActivity;
import com.itboye.mengwu.app.ui.aizhiwu.AizhiwuMengShiGuangItemFragment;
import com.itboye.mengwu.app.ui.mymeng.FollowActivity;
import com.itboye.mengwu.app.ui.mymeng.MessageActivity;
import com.itboye.mengwu.app.ui.mymeng.personsettings.SettingActivity;
import com.itboye.mengwu.app.ui.web.WebActivity;
import com.itboye.mengwu.data.model.AppConfigModel;
import com.itboye.mengwu.data.model.BabyBean;
import com.itboye.mengwu.data.model.GridViewBean;
import com.itboye.mengwu.data.model.VIPPersonalBean;
import com.itboye.mengwu.data.presenter.AddGoodsPresenter;
import com.itboye.mengwu.data.presenter.BabyPresenter;
import com.itboye.mengwu.data.presenter.ConfigAppPresenter;
import com.itboye.mengwu.widget.MyGridView;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Observable;
import java.util.Observer;

/**
 * 我萌Fragment
 *
 * @author dsawe
 */
public class WoMengFragment extends BaseFragment implements ScrollViewListener,
        OnClickListener, Observer {
    /**
     * 设置
     **/
    private ImageView imgSetting;
    private MyGridView gridview_top;
    private ArrayList<GridViewBean> list;
    RelativeLayout adddress_manage;
    private RoundImageView roundImage;
    private LinearLayout linDaiFuKuan;
    private LinearLayout linDaiSongHuo;
    private LinearLayout linDaiPingJia;
    private LinearLayout linShouHou;
    private LinearLayout lin_mengbi;
    private LinearLayout lin_red_bag;
    private LinearLayout lin_daijinquan;
    private LinearLayout lin_yue, line;
    RelativeLayout myCollection, relaout, rel_fensi;
    private ImageView imgXiaoXi, queryPersonData;
    private ImageView imgXiaoXi_read;
    private TextView textGuanZhu, textFenShi;
    ConfigAppPresenter appPresenter;
    AppConfigModel appConfigModel;
    private TextView txtSetTitle;
    private TextView textNum;
    TextView txtUserName;// baby年龄
    private TextView texttextFenShiNum;
    private RoundImageView img_VIP;
    private TextView txtbabys;
    private String uid;
    public ObservableScrollView scroll;
    VIPPersonalBean vipPersonalBean;
    String babybirthday;
    long days;
    String psw;
    long hours;
    long minutes;
    RelativeLayout realyoutTop;
    LinearLayout relyoutHeder;
    LinearLayout relyoutHederNoLogin, view;
    BabyBean baby;
    TextView txtsex;
    BabyPresenter babyPresenter;
    RelativeLayout relativeLayout1, relaDingDan, two, mytime_lin, myred_lin,
            Myblance_lin, help_lin;
    LinearLayout head;
    TextView address_tv, mengbiNum;
    String APP_URL = "http://www.moodwo.com/index.php/Webview";
    // 联系电话
    TextView txtphone_num;
    View hor_view;
    String sex;
    RelativeLayout lianxiMe_rel;

    private int url[] = {R.drawable.myshoucang, R.drawable.qianbao,
            R.drawable.haoyou, R.drawable.zengsong, R.drawable.tiezi,
            R.drawable.shiguangji, R.drawable.naifen, R.drawable.helpcenter};
    private String Countext[] = {"我的收藏", "我的钱包", "邀请好友", "我的赠送", "我的帖子",
            "积分商城", "宝宝乐", "客服中心"};

    @Override
    public int initView() {
        // TODO Auto-generated method stub
        return R.layout.fragment_womeng;
    }

    public static String AVARTACTION = "com.itboye.avart";

    public static String EMAILACTION = "com.itboye.email";

    RelativeLayout realyoutLongin;
    /**
     * 当未登录的时候点击的button
     */
    private ImageView loginnow, registnow;
    String numuid;

    @Override
    public void onMyActivityCreated() {
        appPresenter = new ConfigAppPresenter(this);
        // view.setBackgroundColor(getResources().getColor(R.color.main_color));
        // realyoutTop.getBackground().setAlpha(0);
        judgeIsLogin();
        IntentFilter filter = new IntentFilter("change_img");
        getActivity().registerReceiver(receiver, filter);
        IntentFilter readed = new IntentFilter("readed");
        getActivity().registerReceiver(gonereceiver, readed);
        babyPresenter = new BabyPresenter(this);
        uid = SPUtils.get(getActivity(), null, SpPublicParams.UID, "") + "";
   String      string = SPUtils.get(getActivity(), null, SpPublicParams.SESSION_CODE, "") + "";
        Log.d("uiduiduiduid",string);
        psw = SPUtils.get(getActivity(), null, SpPublicParams.PASSWORD, "")
                + "";
        appConfigModel = new AppConfigModel();

        babyPresenter.BabyAll(SPUtils.get(getActivity(), null,
                SpPublicParams.UID, "") + "");
        vipPersonalBean = new VIPPersonalBean();
        vipPersonalBean.setId(SPUtils.get(getActivity(), null,
                SpPublicParams.UID, "") + "");
        appPresenter.getGuanZhu(
                SPUtils.get(getActivity(), null, SpPublicParams.UID, "") + "",
                null);
        // XImageLoader.load(GlobalConfig.API_URL + "/picture/index?id="
        // + vipPersonalBean.getHead(), roundImage);

        appPresenter.getInfo(appConfigModel);
        // // appPresenter.getGuanZhu(uid);
        // System.out.println("UId" + uid);

        // texttextFenShiNum.setText("0");
        // judgeIsLogin();
        // baby = (BabyBean)
        // getActivity().getIntent().getSerializableExtra("model");
        // NoUnderlineSpan span = new NoUnderlineSpan();
        // if (txtphone.getText() instanceof Spannable) {
        // Spannable s = (Spannable) txtphone.getText();
        // s.setSpan(span, 0, s.length(), Spanned.SPAN_MARK_MARK);
        // }

        realyoutTop = (RelativeLayout) getView().findViewById(R.id.realyoutTop);

        //
        scroll.setScrollViewListener(this);
        // 注册广播
        IntentFilter intentFilterAvart2 = new IntentFilter("changeavart");
        getActivity().registerReceiver(avartBroadcastReceiver,
                intentFilterAvart2);

        // 注册广播
        IntentFilter intentFilterAvart = new IntentFilter(AVARTACTION);
        getActivity().registerReceiver(avartBroadcastReceiver,
                intentFilterAvart);

        // 注册广播
        // IntentFilter intentFilterAvartLongin = new
        // IntentFilter("loginmymengwu");
        // getActivity().registerReceiver(avartBroadcastReceiverLongin,
        // intentFilterAvartLongin);
        onViewPager();
        onGridViewOncelic();
        textFenShi.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                Intent intent = new Intent(getActivity(), FollowActivity.class);
                startActivity(intent);

            }
        });
        adddress_manage.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                LoginController.onAddress(getActivity(), null);
            }
        });
        address_tv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                LoginController.onAddress(getActivity(), null);
            }
        });

        //
        relaDingDan.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                // Intent intent = new Intent(getActivity(),
                // QueryAllOrder.class);
                // startActivity(intent);
                LoginController.MyAllOrder(getActivity(), null);
            }
        });
        loginnow.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                    Intent intent=new Intent(getActivity(),LoginActivity.class);
                    startActivity(intent);
//                LoginController.onButton(getActivity(), null);
            }
        });
        registnow.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent intent = new Intent(MainApplication.context,
                        RegiterActivity.class);
                startActivity(intent);
            }
        });

        //

    }

    // BroadcastReceiver avartBroadcastReceiverLongin = new BroadcastReceiver()
    // {
    // public void onReceive(Context context, Intent intent) {
    // if (uid == null || uid == "") {
    // ByAlert.alert("已经登录");
    // title_rell.setVisibility(View.VISIBLE);
    // realyoutLongin.setVisibility(View.GONE);
    // } else if (uid != null || uid != "") {
    // title_rell.setVisibility(View.GONE);
    // realyoutLongin.setVisibility(View.VISIBLE);
    // ByAlert.alert("请登录");
    // }
    // };
    // };
    BroadcastReceiver avartBroadcastReceiver = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            String resultData = (String) SPUtils.get(getActivity(), null,
                    SpPublicParams.USERHEAD, "");

            try {
                sex = (String) SPUtils.get(getActivity(), null,
                        SpPublicParams.SEX, "");
            } catch (Exception e) {
                // TODO: handle exception
                sex = SPUtils.get(getActivity(), null, SpPublicParams.SEX, 0)
                        + "";
            }
            if (resultData == null && "".equals(resultData)) {

                if ("1".equals(sex)) {
                    roundImage.setImageResource(R.drawable.male);
                } else {
                    roundImage.setImageResource(R.drawable.female);
                }
            } else {
                XImageLoader.load(resultData, roundImage);
            }

            // XImageLoader.load(GlobalConfig.API_URL + "/picture/index?id="
            // + vipPersonalBean.getHead(), roundImage);
            judgeIsLogin();
        }

        ;
    };

    public void judgeIsLogin() {

        String LoginUid = SPUtils.get(MainApplication.context, null,
                SpPublicParams.UID, "") + "";
        Log.e("hu  uid", LoginUid);
        if (LoginUid == null || LoginUid == "") {
            relyoutHeder.setVisibility(View.GONE);
            relyoutHederNoLogin.setVisibility(View.VISIBLE);
            myCollection.setVisibility(View.GONE);
            rel_fensi.setVisibility(View.GONE);
            hor_view.setVisibility(View.GONE);

        } else if (LoginUid != null || LoginUid != "") {
            relyoutHeder.setVisibility(View.VISIBLE);
            relyoutHederNoLogin.setVisibility(View.GONE);
            myCollection.setVisibility(View.VISIBLE);
            rel_fensi.setVisibility(View.VISIBLE);
            hor_view.setVisibility(View.VISIBLE);
            appPresenter.getGuanZhu(
                    SPUtils.get(getActivity(), null, SpPublicParams.UID, "")
                            + "", null);
        }
    }

    public void onScroll(AbsListView listView, int firstVisibleItem,
                         int visibleItemCount, int totalItemCount) {
        if (firstVisibleItem == 0) {
            // 获取头布局
            View view = listView.getChildAt(0);
            if (view != null) {
                // 获取头布局现在的最上部的位置的相反数
                int top = -view.getTop();
                // 获取头布局的高度
                int headerHeight = view.getHeight();
                Log.i("info", "firstVisibleItem  " + firstVisibleItem + ",top:"
                        + top + ",headerHeight:" + headerHeight);
                // 满足这个条件的时候，是头布局在XListview的最上面第一个控件的时候，只有这个时候，我们才调整透明度
                if (top <= headerHeight && top >= 0) {
                    // 获取当前位置占头布局高度的百分比
                    float f = (float) top / (float) headerHeight;
                    realyoutTop.getBackground().setAlpha((int) (f * 255));
                    // 通知标题栏刷新显示
                    // realyoutWoMengTop.invalidate();
                }
            }
            // } else if (firstVisibleItem > 0) {
            // // rl_title.setBackgroundColor(Color.argb(255, 0, 00, 0));
            // txtSetTitle.getBackground().setAlpha(255);
            // } else {
            // txtSetTitle.getBackground().setAlpha(0);
            // }
        }

    }

    public void onScrollStateChanged(AbsListView arg0, int arg1) {
    }

    // @Override
    // public void onStart() {
    // // TODO Auto-generated method stub
    // super.onStart();
    // babyPresenter.BabyAll(SPUtils.get(getActivity(), null,
    // SpPublicParams.UID, "") + "");
    // // appPresenter.getInfo(appConfigModel);
    // // appPresenter.getGuanZhu(SPUtils.get(getActivity(), null,
    // // SpPublicParams.UID, "") + "");
    // }

    public void onViewPager() {
        list = new ArrayList<GridViewBean>();
        for (int i = 0; i < url.length; i++) {
            GridViewBean bean = new GridViewBean();
            bean.setCountext(Countext[i]);
            bean.setUrl(url[i]);
            list.add(bean);

        }

        MyMengAdapter adapter1 = new MyMengAdapter(list, getActivity());
        gridview_top.setAdapter(adapter1);

    }

    /****
     * gridview点击事件，获取gridview的下标进行跳转
     */
    public void onGridViewOncelic() {

        gridview_top.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1,
                                    int position, long arg3) {
                // TODO Auto-generated method stub

                if (position == 0) {

                    //
                    LoginController.queryMyCollection(getActivity(), null);
                } else if (position == 1) {
                    /*
                     * w我的动态
					 */
                    // uid = SPUtils.get(getActivity(), null,
                    // SpPublicParams.UID,
                    // "") + "";
                    // psw = SPUtils.get(getActivity(), null,
                    // SpPublicParams.PASSWORD, "") + "";
                    // String urlString =
                    // "http://www.moodwo.com/index.php/Webview/Index/mengbi?uid="
                    // + uid + "&psw=" + psw + "";
                    // Log.e("hu", "uid=" + uid + "pse=" + psw);
                    // LoginController.onMengBi(getActivity(), "萌币", urlString);
                    LoginController.onSmall(getActivity(), null);

                } else if (position == 2) {
                    // ByAlert.alert(uid + "lingjie==" + APP_URL
                    // + "/invite/index?uid=" + uid + "&psw=" + psw + "");
                    uid = SPUtils.get(getActivity(), null, SpPublicParams.UID,
                            "") + "";
                    psw = SPUtils.get(getActivity(), null,
                            SpPublicParams.PASSWORD, "") + "";
                    LoginController.InvitationPrize(getActivity(), "邀请好友",
                            APP_URL + "/invite/index?uid=" + uid + "&psw="
                                    + psw + "");

                } else if (position == 3) {

                    LoginController.MengTime(getActivity(), null);// 萌时光不需要登陆，我的赠送用mengtime

                } else if (position == 4) {
                    LoginController.onMyTieZi(getActivity(), null);

                } else if (position == 5) {

                    uid = SPUtils.get(getActivity(), null, SpPublicParams.UID, "") + "";
                    psw = SPUtils.get(getActivity(), null, SpPublicParams.PASSWORD, "") + "";
                    if (uid.equals("")) {
                        Intent intent = new Intent(getActivity(), LoginActivity.class);
                        startActivity(intent);
                    } else {
                        Intent intent = new Intent(getActivity(),
                                WebActivity.class);
                        intent.putExtra("title", "积分商城");
                        intent.putExtra("url", "http://www.moodwo.com/index.php/Webview/ScoreGoods/index?uid=" + uid + "&psw=" + psw);
                        getActivity().startActivity(intent);
                    }

                    //

                } else if (position == 6) {
                    // /**
                    // * 我的评价
                    // */
                    // Intent intent = new Intent(getActivity(),
                    // MePingJiaFragment.class);
                    // getActivity().startActivity(intent);
                    // LoginController.MePingjia(getActivity(), null);
                    LoginController.woDeDongTai(getActivity(), null);

                } else if (position == 7) {
                    uid = SPUtils.get(getActivity(), null, SpPublicParams.UID,
                            "") + "";
                    psw = SPUtils.get(getActivity(), null,
                            SpPublicParams.PASSWORD, "") + "";
                    String helpString = APP_URL + "/help?uid=" + uid + "&psw="
                            + psw + "";
                    LoginController.Help(getActivity(), "客服中心", helpString);
                    // Intent intent = new Intent(getActivity(),
                    // WebActivity.class);
                    // intent.putExtra("title", "帮助中心");
                    // intent.putExtra("url", APP_URL + "/help?uid=" + uid
                    // + "&psw=" + psw + "");
                    //
                    // getActivity().startActivity(intent);
                }

            }
        });
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch (v.getId()) {

            case R.id.mytime_lin:
                uid = SPUtils.get(getActivity(), null, SpPublicParams.UID, "") + "";
                psw = SPUtils.get(getActivity(), null, SpPublicParams.PASSWORD, "")
                        + "";
                if (uid.equals("")) {
                    Intent intent = new Intent(getActivity(), LoginActivity.class);
                    startActivity(intent);
                } else {
                    Intent intent = new Intent(getActivity(),
                            AizhiwuMengShiGuangItemFragment.class);
                    getActivity().startActivity(intent);
                }
                break;
            case R.id.myred_lin:
                uid = SPUtils.get(getActivity(), null, SpPublicParams.UID, "") + "";
                psw = SPUtils.get(getActivity(), null, SpPublicParams.PASSWORD, "")
                        + "";
                String urlString = "http://www.moodwo.com/index.php/Webview/Index/mengbi?uid="
                        + uid + "&psw=" + psw + "";
                Log.e("hu", "uid=" + uid + "pse=" + psw);
                LoginController.onMengBi(getActivity(), "萌币", urlString);
                break;
            case R.id.Myblance_lin:
                LoginController.onSmall(getActivity(), null);
                break;
            case R.id.help_lin:

                uid = SPUtils.get(getActivity(), null, SpPublicParams.UID, "") + "";
                psw = SPUtils.get(getActivity(), null, SpPublicParams.PASSWORD, "") + "";
                if (uid.equals("")) {
                    Intent intent = new Intent(getActivity(), LoginActivity.class);
                    startActivity(intent);
                } else {
                    Intent intent = new Intent(getActivity(), YouHuiQuanActivity.class);
                    startActivity(intent);
                }
//			LoginController.Help(getActivity(), "客服中心", helpString);
                break;
            case R.id.linShouHou:
                LoginController.onOrder(getActivity(), null);

                break;
            case R.id.linDaiPingJia:
                LoginController.onPingjia(getActivity(), null);
                break;
            case R.id.linDaiSongHuo:
                LoginController.onShouHuo(getActivity(), null);
                break;
            case R.id.linDaiFuKuan:
                LoginController.onFukuan(getActivity(), null);
                break;
            case R.id.imgSetting:
                Intent intent2 = new Intent(getActivity(), SettingActivity.class);
                startActivity(intent2);
                break;
            case R.id.roundImage:
                LoginController.gotoGerenKongjian(getActivity(), uid);
                break;
            case R.id.txtphone_num:
                Intent intent3 = new Intent();
                intent3.setAction(Intent.ACTION_CALL);
                // url:统一资源定位符
                // uri:统一资源标示符（更广）
                intent3.setData(Uri.parse("tel:" + phone));
                startActivity(intent3);
                break;

            case R.id.imgXiaoXi:
                // LoginController.QuanMessge(getActivity(), null);
                Intent xiaoxi = new Intent(getActivity(), MessageActivity.class);
                startActivity(xiaoxi);
                break;
            case R.id.imgXiaoXi_read:
                LoginController.QuanMessge(getActivity(), null);
                break;
            case R.id.textGuanZhu:
                LoginController.guanzhu(getActivity(), null);
                break;
            case R.id.queryPersonData:
                LoginController.queryMyMessae(getActivity(), null);
                break;
            // case R.id.lin_daijinquan:
            // LoginController.onDaiJinQuan(getActivity(), null);
            // break;
            case R.id.img_VIP:
                uid = SPUtils.get(getActivity(), null, SpPublicParams.UID, "") + "";
                psw = SPUtils.get(getActivity(), null, SpPublicParams.PASSWORD, "")
                        + "";
                LoginController.vip(getActivity(), "会员", APP_URL
                        + "/vip/index?uid=" + uid + "&psw=" + psw + "");

                break;
            default:
                break;
        }
    }

    @Override
    public void onResume() {
        // TODO Auto-generated method stub
        super.onResume();

        babyPresenter.BabyAll(SPUtils.get(getActivity(), null,
                SpPublicParams.UID, "") + "");
        appConfigModel = new AppConfigModel();
        appPresenter = new ConfigAppPresenter(this);
        appPresenter.getInfo(appConfigModel);
        // // appPresenter.getGuanZhu(uid);
        // System.out.println("UId" + uid);
        vipPersonalBean = new VIPPersonalBean();
        vipPersonalBean.setId(SPUtils.get(getActivity(), null,
                SpPublicParams.UID, "") + "");
        appPresenter.getGuanZhu(
                SPUtils.get(getActivity(), null, SpPublicParams.UID, "") + "",
                null);
    }

    AddGoodsPresenter detailPresenter;
    // private String uid;
    private String phone;
    String guanzhu;
    String fensi;

    // String head;

    String babyAge;

    Date currentTime = new Date();
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String date1 = formatter.format(currentTime);

    // .setText(date2);
    public static String formatData(String dataFormat, long timeStamp) {
        if (timeStamp == 0) {
            return "";
        }
        timeStamp = timeStamp * 1000;
        String result = "";
        SimpleDateFormat format = new SimpleDateFormat(dataFormat);
        result = format.format(new Date(timeStamp));
        return result;
    }

    public void onData() {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        try {
            Date d1 = df.parse(date1);
            Date d2 = df.parse(babyAge);
            long diff = d1.getTime() - d2.getTime();// 这样得到的差值是微秒级别

            days = diff / (1000 * 60 * 60 * 24);
            System.out
                    .println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>DaTa:\t\t\t\t\t\t\t\t"
                            + days);
            txtbabys.setText("" + days);

        } catch (Exception e) {
        }

    }

    private void upbabyname(String data) {
        // TODO Auto-generated method stub
        txtUserName.setText(data);
    }

    ;

    @SuppressWarnings("unchecked")
    @Override
    public void update(Observable observable, Object data) {
        ResultEntity entity = handlerError(data);
        if (entity != null) {
            if (entity.getEventType() == BabyPresenter.BABYALL_success) {
                ArrayList<BabyBean> baby;
                baby = (ArrayList<BabyBean>) entity.getData();
                if (baby.size() > 0) {
                    for (int i = 0; i < baby.size(); i++) {
                        if ("1".equals(baby.get(i).getIs_default())) {
                            String babynameString = baby.get(i).getBirthday();
                            upbabyname(babybirth(babynameString));
                        } else if ("0".equals(baby.get(i).getIs_default())) {
                            String babynameString = baby.get(0).getBirthday();
                            upbabyname(babybirth(babynameString));
                        }
                    }
                } else {
                    txtsex.setText("暂时还没宝宝信息哦");
                    txtUserName.setVisibility(View.GONE);
                }

            }

            if (entity.getEventType() == ConfigAppPresenter.ConfigApp_success) {
                appConfigModel = (AppConfigModel) entity.getData();
                phone = appConfigModel.getCustomerPhone().get(0).getValue();
                txtphone_num.setText(appConfigModel.getCustomerPhone().get(0)
                        .getValue());
                SPUtils.put(getActivity(), null, SpPublicParams.KeFuPhone,
                        phone);
                lianxiMe_rel.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        ByAlert.alert("123");
                        Intent intent2 = new Intent();
                        intent2.setAction(Intent.ACTION_CALL);
                        // url:统一资源定位符
                        // uri:统一资源标示符（更广）
                        intent2.setData(Uri.parse("tel:"
                                + SPUtils.get(getActivity(), null,
                                SpPublicParams.KeFuPhone, "")));
                        startActivity(intent2);
                    }
                });
            }
            if (entity.getEventType() == ConfigAppPresenter.Guanzhu_success) {
                vipPersonalBean = (VIPPersonalBean) entity.getData();
                if (vipPersonalBean != null) {
                    guanzhu(vipPersonalBean.getFocus(),
                            vipPersonalBean.getBeFocus());
                    vip(vipPersonalBean.getVip().getGroup_title());
                    SPUtils.put(getActivity(), null, SpPublicParams.ALIPAY,
                            vipPersonalBean.getAlipay());
                    SPUtils.put(getActivity(), null, SpPublicParams.VIP,
                            vipPersonalBean.getVip().getGroup_title());

                    // if (SPUtils.get(getActivity(), null, SpPublicParams.USERHEAD,
                    // "") == "" && "0".equals(vipPersonalBean.getSex())) {
                    // roundImage.setImageResource(R.drawable.female);
                    // SPUtils.put(getActivity(), null, SpPublicParams.SEX,
                    // vipPersonalBean.getSex());
                    // } else if (SPUtils.get(getActivity(), null,
                    // SpPublicParams.USERHEAD, "") == ""
                    // && "1".equals(vipPersonalBean.getSex())) {
                    // roundImage.setImageResource(R.drawable.male);
                    // SPUtils.put(getActivity(), null, SpPublicParams.SEX,
                    // vipPersonalBean.getSex());
                    // } else {
                    // XImageLoader.load((String) SPUtils.get(getActivity(), null,
                    // SpPublicParams.USERHEAD, ""), roundImage);
                    // }
                    // XImageLoader.load((String) SPUtils.get(getActivity(), null,
                    // SpPublicParams.USERHEAD, ""), roundImage);
                    if (SPUtils.get(getActivity(), null, SpPublicParams.USERHEAD,
                            "") == ""
                            || vipPersonalBean.getHead() == null
                            || "".equals(vipPersonalBean.getHead())) {
                        if ("1".equals(vipPersonalBean.getSex())) {
                            roundImage.setImageResource(R.drawable.male);
                        } else {
                            roundImage.setImageResource(R.drawable.female);
                        }
                    } else {
                        XImageLoader.load((String) SPUtils.get(getActivity(), null,
                                SpPublicParams.USERHEAD, ""), roundImage);
                    }
                    txtSetTitle.setText(vipPersonalBean.getNickname());
                    mengBi(vipPersonalBean.getScore());
                    // Log.e("hu..", vipPersonalBean.getAddressDefault() + "");
                    // Log.e("hu..add2", vipPersonalBean.getAddressDefault()
                    // .getProvince() + "");
                    // Log.e("hu..add3",
                    // vipPersonalBean.getAddressDefault().getCity()
                    // + "");
                    if ("".equals(vipPersonalBean.getAddressDefault().getProvince())
                            || null == vipPersonalBean.getAddressDefault()
                            .getProvince()) {

                        address_tv.setText("您还没有收货地址，请添加");
                    } else {

                        address_tv.setText(vipPersonalBean.getAddressDefault()
                                .getProvince()
                                + vipPersonalBean.getAddressDefault().getCity()
                                + vipPersonalBean.getAddressDefault().getArea()
                                + vipPersonalBean.getAddressDefault()
                                .getDetailinfo());
                    }
                }
                // SPUtils.put(getActivity(), null, SpPublicParams.USERHEAD,
                // vipPersonalBean.getHead());
                // SPUtils.put(getActivity(), null, SpPublicParams.USERHEAD,
                // "http://api.moodwo.com/public/index.php/Picture/index?id="
                // + vipPersonalBean.getHead());
                // Log.e("hu--head", vipPersonalBean.getHead());
            }
        } else {
            // ByAlert.alert("数据解析错");
        }
    }

    public static void setPosition() {
        // scroll.smoothScrollTo(0, 0);
    }

    void mengBi(String num) {
        mengbiNum.setText(num);
    }

    void guanzhu(String guan, String num) {
        guanzhu = guan;
        fensi = num;
        textNum.setText(guan);
        texttextFenShiNum.setText(num);
    }

    void vip(String string) {
        if (string.equals("vip2")) {
            img_VIP.setBackgroundResource(R.drawable.vip2_1);
        } else if (string.equals("vip1")) {
            img_VIP.setBackgroundResource(R.drawable.vip1_img);
            // img_VIP.setBackground(getResources().getDrawable(R.drawable.vip001));
        } else {
            img_VIP.setBackgroundResource(R.drawable.vip2_2);
        }

        onData();
        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>"
                + vipPersonalBean.getBabyDefault().getBirthday());

    }

    @Override
    public void onScrollChanged(ObservableScrollView scrollView, int x, int y,
                                int oldx, int oldy) {

        // int yyy= line.getHeight()- scroll.getHeight();
        // realyoutTop.getBackground().setAlpha(255*y/yyy);

    }

    String babybirth(String birth) {
        SimpleDateFormat myFmt1 = new SimpleDateFormat("yyyy年MM月dd日");
        Calendar calendar = Calendar.getInstance();
        int yearNow = calendar.get(Calendar.YEAR);
        int monthNow = calendar.get(Calendar.MONTH);
        int dayNow = calendar.get(Calendar.DAY_OF_MONTH);
        Calendar calendar2 = Calendar.getInstance();
        if (birth != null) {
            long timews = Long.valueOf(birth);
            Date date = new Date(timews * 1000L);
            calendar2.setTime(date);
            int yearBirth = calendar2.get(Calendar.YEAR);
            int monthBirth = calendar2.get(Calendar.MONTH);
            int dayBirth = calendar2.get(Calendar.DAY_OF_MONTH);
            int age = yearNow - yearBirth;
            int month = monthNow - monthBirth;
            int day = dayNow - dayBirth;
            if (day < 0) {
                month -= 1;
                calendar2.add(Calendar.MONTH, -1);// 得到上一个月，用来得到上个月的天数。
                day = day + calendar2.getActualMaximum(Calendar.DAY_OF_MONTH);
            }
            if (month < 0) {
                month = (month + 12) % 12;
                age--;
            }
            int days = day + 1;
            int months = month + 1;
            if (age == 0) {
                if (month == 0) {
                    babybirthday = (days + "天");
                } else {
                    babybirthday = (months + "月" + days + "天");
                }
            } else {
                if (month == 0) {
                    babybirthday = (age + "岁" + days + "天");
                } else {
                    babybirthday = (age + "岁" + months + "月" + days + "天");
                }
            }
        }
        return babybirthday;
    }

    BroadcastReceiver receiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            // TODO Auto-generated method stub
            visiable();
        }

    };
    BroadcastReceiver gonereceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            // TODO Auto-generated method stub
            Gone();
        }

    };

    void visiable() {
        imgXiaoXi_read.setVisibility(View.VISIBLE);
        imgXiaoXi.setVisibility(View.GONE);

    }

    void Gone() {
        imgXiaoXi_read.setVisibility(View.GONE);
        imgXiaoXi.setVisibility(View.VISIBLE);

    }

}
